import request from '@/utils/request';
import { AdminTableListParams, AdminTableListItem, UpdateRoleParams } from './adminData.d';



/**
 * 根据条件分页查询管理员列表
 * @param params 查询条件
 */
export async function queryAdmin(params?: AdminTableListParams) {
    return request('/api/ums/admin', {
        method: 'GET',
        params,
    });
}


/**
 * 新增管理员
 * @param params /api/ums/adminTableListItem
 */
export async function addAdmin(params: AdminTableListItem) {
    return request('/api/ums/admin', {
        method: 'POST',
        data: {
            ...params,
        },
    });
}

/**
 * 更新管理员
 * @param params /api/ums/adminTableListItem
 */
export async function updateAdmin(params: AdminTableListParams) {
    return request(`/api/ums/admin/${params.adminId}`, {
        method: 'PUT',
        data: {
            ...params,
        },
    });
}


/**
 * 详情管理员
 * @param params 主键
 */
export async function getAdmin(params:{ id: string }) {
    return request(`/api/ums/admin/${params.id}`, {
        method: 'GET',
    });
}

/**
 * 详情管理员
 * @param params 主键
 */
export async function getAdminDetail(params:{
    [key: string]: any;
}) {
    return request(`/api/ums/adminDetail/${params.id}`, {
        method: 'GET',
    });
}
/**
 * 详情管理员角色
 * @param params id
 */
export async function getAdminRoles(params:{ id: string }) {
    return request(`/api/ums/admin/roles/${params.id}`, {
        method: 'GET',
    });
}

/**
 * 删除管理员
 * @param params 主键
 */
export async function removeAdmin(params: { id: string|undefined }) {
    return request(`/api/ums/admin/${params.id}`, {
        method: 'DELETE',
        data: {
            ...params,
        },
    });
}

/**
 * 删除管理员
 * @param params 主键数组
 */
export async function removeBatchAdmin(params: { ids: (string|undefined)[] }) {
    return request('/api/ums/admin', {
        method: 'DELETE',
        data: {
            ...params,
        },
    });
}

export async function updateAdminRole(params:UpdateRoleParams) {
    return request('/api/ums/admin/roles/relation', {
        method: 'POST',
        data: {
            ...params,
        },
    });
}
export async function getAdminRolesSelectItems() {
    return request('/api/ums/adminRoles/selectItems', {
        method: 'GET',
    });
}
